# Generated Cmake Pico project file

cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)
set(PICO_SDK_PATH "G:/Some_thing_to_do/69_RP2040/sdk/pico-sdk")
set(PICO_BOARD pico CACHE STRING "Board type")
set(USER_APP_PATH user)

# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)
# include(FreeRTOS_Kernel_import.cmake)

if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0")
  message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()

project(freertos_tml C CXX ASM)

# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()


# *****************************************************************************
# import freertos
add_library(freertos_config INTERFACE)
target_include_directories(freertos_config SYSTEM
INTERFACE
    user/config
)
target_compile_definitions(freertos_config
  INTERFACE
    projCOVERAGE_TEST=0
)
set(FREERTOS_HEAP "4" CACHE STRING "" FORCE)
set(FREERTOS_PORT "GCC_ARM_CM0" CACHE STRING "" FORCE)
add_subdirectory(thirdparty/freertos/FreeRTOS-Kernel)

# *****************************************************************************
# import lvgl，参考官方文档：https://docs.lvgl.io/master/get-started/platforms/cmake.html
set(LV_CONF_PATH
    ${CMAKE_CURRENT_SOURCE_DIR}/user/config/lv_conf.h
    CACHE STRING "" FORCE)
add_subdirectory(thirdparty/lvgl)

add_subdirectory(thirdparty/tslib)

# *****************************************************************************
# import driver
add_subdirectory(user/driver)

# *****************************************************************************
# import ports
add_subdirectory(user/ports)

# *****************************************************************************
# App
add_subdirectory(user/app)


# Add executable. Default name is the project name, version 0.1
add_executable(freertos_tml ${USER_APP_PATH}/freertos_tml.c )

pico_set_program_name(freertos_tml "freertos_tml")
pico_set_program_version(freertos_tml "0.1")

pico_enable_stdio_uart(freertos_tml 1)
pico_enable_stdio_usb(freertos_tml 0)

# Add the standard library to the build
target_link_libraries(freertos_tml
    pico_stdlib
    freertos_kernel
    lvgl
    lvgl_demos
    lvgl_examples
    user_driver
    user_ports
    app
    tslib)

# lvgl 库需要依赖 freertos/user_ports 下的头文件
target_link_libraries(lvgl freertos_kernel user_ports)

# Add the standard include files to the build
target_include_directories(freertos_tml PRIVATE
  ${CMAKE_CURRENT_LIST_DIR}
  ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required
  ${CMAKE_CURRENT_LIST_DIR}/${USER_APP_PATH}
  ${CMAKE_CURRENT_LIST_DIR}/${USER_APP_PATH}/ports
  ${CMAKE_CURRENT_LIST_DIR}/${USER_APP_PATH}/config
  ${CMAKE_CURRENT_LIST_DIR}/${USER_APP_PATH}/app
  ${CMAKE_CURRENT_LIST_DIR}/thirdparty/tslib
  ${CMAKE_CURRENT_LIST_DIR}/thirdparty/lvgl
  ${CMAKE_CURRENT_LIST_DIR}/thirdparty/freertos/FreeRTOS-Kernel/include
)

# Add any user requested libraries
target_link_libraries(freertos_tml
        hardware_spi
        hardware_i2c
        hardware_dma
        hardware_pio
        hardware_interp
        hardware_timer
        hardware_watchdog
        hardware_clocks
        )

target_compile_definitions(freertos_tml PRIVATE
    mainRUN_FREE_RTOS_ON_CORE=1
    PICO_STACK_SIZE=0x1000
    PICO_STDIO_STACK_BUFFER_SIZE=64 # use a small printf on stack buffer
    PICO_DEFAULT_UART_TX_PIN=16
    PICO_DEFAULT_UART_RX_PIN=17
    PICO_DEFAULT_UART=0
)

pico_add_extra_outputs(freertos_tml)

